package com.garvin.spring.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.garvin.spring.dto.AdminInfoResponseDto;
import com.garvin.spring.dto.BaseResponseDto;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author garvin
 */
@RestController
public class TestController {

    @PostMapping("/admin/login")
    public String login(@RequestBody LoginParam loginParam) {
        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode objectNode = objectMapper.createObjectNode();
        if ("admin".equalsIgnoreCase(loginParam.getUser_name())
                && "123456".equalsIgnoreCase(loginParam.getPassword())) {
            objectNode.put("status", 1);
        } else {
            objectNode.put("status", 0);
            objectNode.put("message", "用后名和密码不正确");
        }
        return objectNode.toString();
    }

    @Data
    public static class LoginParam {
        private String user_name, password;
    }

    @GetMapping("/admin/info")
    public BaseResponseDto getAdminInfo() {
        AdminInfoResponseDto responseDto = new AdminInfoResponseDto();
        responseDto.setStatus(1);
        return responseDto;
    }

}
